package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Team;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.TeamService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 teamController
//@RequestMapping("/teamController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /teamController
public class TeamController {
	@Resource
    TeamService teamService;

	@GetMapping("/getAllteam")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Team> getAllTeam() throws Exception{
    	System.out.println("查询全部球队");
    	return teamService.getAllTeams();
    }

	@PostMapping("/addteam")
	@ResponseBody
	public DTO<Team> addTeam(@RequestBody Team team) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加球队成功");
		return teamService.addTeam(team);
	}
	@DeleteMapping("/deleteteam/{tno}")
	@ResponseBody
    public DTO<Team> deleteTeamByTno(@RequestBody @PathVariable("tno") String tno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(tno+"删除球队成功");
    	return teamService.deleteTeamByTno(tno);
    }

	@GetMapping("/teamBy/{tno}")
	@ResponseBody
	public DTO<Team> getTeamByTno(@PathVariable("tno") String tno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(tno+"根据主键查询球队成功");
		return teamService.getTeamByTno(tno);
	}

	@PatchMapping("/updateteam")
	@ResponseBody
	public DTO<Team> updateTeamByTno(@RequestBody Team team) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改球队成功");
		System.out.println(team);
		return teamService.updateTeamByTno(team);
	}

	@RequestMapping("/team/pageInfo")
	@ResponseBody
	public DTO<Team> getTeamByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return teamService.getTeamByPage(pageInfo);
	}

}
